package com.ruoyi.yljf.service.impl;

import java.util.List;

import com.ruoyi.yljf.domain.vo.DrugCategoryVO;
import com.ruoyi.yljf.domain.vo.DrugCategoryTypeVO;
import com.ruoyi.yljf.mapper.DrugTypeMapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.yljf.mapper.DrugCategoryMapper;
import com.ruoyi.yljf.domain.DrugCategory;
import com.ruoyi.yljf.service.IDrugCategoryService;

import javax.annotation.Resource;

/**
 * 药材类型Service业务层处理
 * 
 * @author metaee
 * @date 2025-03-11
 */
@Service
public class DrugCategoryServiceImpl extends ServiceImpl<DrugCategoryMapper, DrugCategory> implements IDrugCategoryService {

    @Resource
    private DrugCategoryMapper drugCategoryMapper;

    @Resource
    private DrugTypeMapper drugTypeMapper;
    
    /**
     * 查询药材类型列表
     * 
     * @param drugCategory 药材类型
     * @return 药材类型
     */
    @Override
    public List<DrugCategory> selectDrugCategoryList(DrugCategory drugCategory) {
    	LambdaQueryWrapper<DrugCategory> queryWrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotNull(drugCategory.getCategoryId())) {
			queryWrapper.eq(DrugCategory::getCategoryId, drugCategory.getCategoryId());
		}
        if (StringUtils.isNotEmpty(drugCategory.getName())) {
			queryWrapper.like(DrugCategory::getName, drugCategory.getName());
		}
        return drugCategoryMapper.selectList(queryWrapper);
    }

    @Override
    public List<DrugCategoryVO> getDrugCategory() {
        List<DrugCategoryVO> drugCategoryVOS = drugCategoryMapper.getDrugCategory(0L);
        drugCategoryVOS.forEach(drugCategoryVO -> {
            List<DrugCategoryTypeVO> dc = drugCategoryMapper.getDrugType(drugCategoryVO.getId());
            drugCategoryVO.setDrugTypelist(dc);
        });
        return drugCategoryVOS;
    }
}
